package com.mylove.judas.yaya.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.BounceInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.mylove.judas.yaya.R;
import com.mylove.judas.yaya.ui.activity.base.BaseActivity;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by Judas on 2017/6/10.
 */

public class WelComeActivity extends BaseActivity {

    private ImageView iv_logo;
    private TextView tv_name;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getToolbarX().hide();
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_welcome;
    }

    @Override
    public void initView() {
        super.initView();

        // Initialize the Mobile Ads SDK.
        MobileAds.initialize(this, "ca-app-pub-8558484944841073~4014823981");

        iv_logo = (ImageView) findViewById(R.id.iv_logo);
        tv_name = (TextView) findViewById(R.id.tv_name);


        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                Intent intent = new Intent(mContext, MainActivity.class);
                startActivity(intent);
                finish();
            }
        }, 4000);
        startAnim();

    }

    /**
     * 启动动画
     */
    public void startAnim(){

        //文字闪出
        AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
        alphaAnimation.setDuration(3000);
        //图片移动，从上往下
        TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT,0.0f,
                Animation.RELATIVE_TO_PARENT,0.0f,
                Animation.RELATIVE_TO_PARENT,-0.5f,
                Animation.RELATIVE_TO_SELF,0);
        animation.setDuration(3000);//设置时长
        //弹起的效果
        animation.setInterpolator(new BounceInterpolator());
        //动画设置到控件中
        iv_logo.setAnimation(animation);
        tv_name.setAnimation(alphaAnimation);
    }

}
